#include <iostream>
#include <stack>
#include <vector>

class MyQueue {
public:
    MyQueue() {

    }
    
    void push(int x) {
        stack1.push(x);
    }
    
    int pop() {
        if(!stack2.empty()) {
            int val = stack2.top(); // 用非引用类型得值接收引用类型得值，会生成临时对象拷贝过去
            stack2.pop();
            return val;
        } else if (!stack1.empty()) {
            while(!stack1.empty()) {
                int val = stack1.top();
                stack1.pop();
                stack2.push(val);
            }
            int val = stack2.top();
            stack2.pop();
            return val;
        } else {
            return NULL;
        }
    }
    
    int peek() {
        if(!stack2.empty()) {
            int val = stack2.top(); // 用非引用类型得值接收引用类型得值，会生成临时对象拷贝过去
            return val;
        } else if (!stack1.empty()) {
            while(!stack1.empty()) {
                int val = stack1.top();
                stack1.pop();
                stack2.push(val);
            }
            int val = stack2.top();
            return val;
        } else {
            return NULL;
        }
    }
    
    bool empty() {
        return stack1.empty() || stack2.empty();
    }

private:
    std::stack<int, std::vector<int>> stack1, stack2;

};

int main() {

}
